package com.hc.core.util;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

public class EhcacheDemo{
	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		EhcacheDemo  ehcacheDemo = new EhcacheDemo();

		
		CacheManager manager = CacheManager.create();
		//1.创建一个缓存
		Cache cache = new Cache("sdsfdxjxw", 1, true, false, 5, 2);
		manager.addCache(cache);

		//2.向Cache对象里添加Element元素，Element元素有key，value键值对组成
		cache.put(new Element("name", "admin"));
		
		
		System.out.println(getCacheValue(manager,"name"));

		//manager.shutdown();
	}
	
	
	public static String getCacheValue(CacheManager manager,String cacheName){
		Cache cache = manager.getCache(cacheName);
		System.out.println(cache.get("name"));
		String value = (String)cache.get("name").getValue();
		
		return value;
	}
}
